package com.redlight.controller;


import com.redlight.base.Global;
import com.redlight.base.RestBaseController;
import com.redlight.base.RestResult;
import com.redlight.bean.Employee;
import com.redlight.cache.EhCacheUtils;
import com.redlight.pool.IPoolRunnableTask;
import com.redlight.pool.PoolArgs;
import com.redlight.pool.ThreadPool;
import com.redlight.pool.ThreadPoolFactory;
import com.redlight.service.EmployeePool;
import com.redlight.service.EmployeeService;
import org.springframework.web.bind.annotation.*;
import com.redlight.utils.StringUtil;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by chao on 2019/1/11.    2021/12/23====11166  888999000888
 * fenzhiceshid1816ddd
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/api/sys/employee")
public class EmployeeController extends RestBaseController {
    @Resource
    private EmployeeService employeeService;

    @Resource
    private ThreadPoolFactory threadPoolFactory;
//
//    @RequestMapping(value = "form/{id}",method = RequestMethod.GET)
//    public RestResult form(@PathVariable("id") String id) {
//        boolean flag = false;
//        Object retObject = "操作失败";
//        try {
//            List list=new ArrayList();
//            int count=0;
//            for(int i=0;i<500;i++){
//                Employee employee=new Employee();
//                employee.preSave();
//                employee.setEmail("2422463940@qq.com");
//                employee.setLastName("张三"+i);
//                employee.setGender(1);
//                list.add(employee);
//
//                if(2000<1000){
//                    employeeService.createBatch(list);
//                }else{
//                    count++;
//                    if(count>=1000){
//                        employeeService.createBatch(list);
//                        list.clear();
//                        count=0;
//                    }
//                }
//
//
//            }
////            employeeService.createBatch(list);
////            if(StringUtil.isNotBlank(id)) {
////                retObject = this.employeeService.get(id);
////                flag = true;
////            }
////            employeeService.get("1");
//        }catch (Exception e){
//            e.printStackTrace();
//            retObject = "操作失败:"+e.getMessage();
//        }
//        return renderResult(flag, flag?Ok:Fail, retObject);
//    }

    @RequestMapping(value = "form/{id}",method = RequestMethod.GET)
    public RestResult form(@PathVariable("id") String id) {
        boolean flag = false;
        Object retObject = "操作失败";
        try {
            if(StringUtil.isNotBlank(id)) {
                retObject = this.employeeService.get(id);
                flag = true;
            }
        }catch (Exception e){
            e.printStackTrace();
            retObject = "操作失败:"+e.getMessage();
        }
        return renderResult(flag, flag?Ok:Fail, retObject);
    }



    @RequestMapping("page")
    public RestResult page() {
        boolean flag = false;
        Object retObject = null;
        try {
//            String orderBy = employee.getPage().getOrderBy();
//            retObject = this.employeeService.findPage(employee);
            flag = true;
        }catch (Exception e){
            e.printStackTrace();
            retObject = "操作失败:"+e.getMessage();
        }
        return renderResult(flag, flag?Ok:Fail, retObject);
    }


    @RequestMapping("save")
    public RestResult save() {
        boolean flag = false;
        Object retObject = null;
        try {
            Employee employee = new Employee();
            employee.setId("123");
            employee.setLastName("an");
            this.employeeService.save1(employee);

//            String orderBy = employee.getPage().getOrderBy();
//            retObject = this.employeeService.findPage(employee);
            flag = true;
        }catch (Exception e){
            e.printStackTrace();
            retObject = "操作失败:"+e.getMessage();
        }
        return renderResult(flag, flag?Ok:Fail, retObject);
    }

    @RequestMapping("cache")
    public RestResult cache() {
        boolean flag = false;
        Object retObject = null;
        try {
            EhCacheUtils.put("test","hello world");
            Object test = EhCacheUtils.get("test");
            System.out.println(test );

            flag = true;
        }catch (Exception e){
            e.printStackTrace();
            retObject = "操作失败:"+e.getMessage();
        }
        return renderResult(flag, flag?Ok:Fail, retObject);
    }
}
